package com.aboverock.module.system.service;

import java.sql.SQLException;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.IService;
import com.aboverock.module.system.domain.Dictionary;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author Rock Wang
 * @since 2018-08-09
 */
public interface DictionaryService extends IService<Dictionary> {

    /**
     * 判断当前字典是否为字典类型.
     *
     * @param dictionary the dictionary
     * @return true, if is dictionary type
     */
    boolean isDictionaryType(Dictionary dictionary);
    
    /**
     * 获取当前字典所属字典类型的code.
     *
     * @param dictionary the dictionary
     * @return the dictionary type code
     */
    public String getDictionaryTypeCode(Dictionary dictionary);

    /**
     * 获取当前字典父节点字典的路径.
     *
     * @param dictionary the dictionary
     * @return the parent dictionary path
     */
    public String getParentDictionaryPath(Dictionary dictionary);

    /**
     * 生成当前字典的字典路径（code拼接）.
     *
     * @param dictionary the dictionary
     * @return the string
     */
    public String generateDictionaryPath(Dictionary dictionary);

    /**
     * 判断当前code在同级字典中是否已存在(不区分大小写).
     *
     * @param dictionary the dictionary
     * @return true, if is duplicated code
     */
    public boolean isDuplicatedCode(Dictionary dictionary);

    /**
     * 更新数据字典信息.
     *
     * @param dictionary the dictionary
     * @param oldDictionary the old dictionary
     * @return true, if successful
     * @throws SQLException the SQL exception
     */
    public boolean update(Dictionary dictionary, Dictionary oldDictionary) throws SQLException;

    /**
     * 删除数据字典或字典类型，删除字典类型时同时删除类型下的数据字典.
     *
     * @param dictionary the dictionary
     * @return true, if successful
     */
    boolean remove(Dictionary dictionary);

    /**
     * 交换两个字典/字典类型的顺序.
     *
     * @param dictionary1 the dictionary 1
     * @param dictionary2 the dictionary 2
     * @return true, if successful
     * @throws SQLException the SQL exception
     */
    public boolean exchangeOrderNo(Dictionary dictionary1, Dictionary dictionary2)
            throws SQLException;

    /**
     * 将查询到的字典及其子字典封装成Tree结构.
     *
     * @param dictionaries the dictionaries
     * @return the dictionary
     */
    public Dictionary buildTree(List<Dictionary> dictionaries);

    /**
     * 获取所有字典类型.
     *
     * @return the dictionary type
     */
    public List<Dictionary> getAllDictionaryType();

    /**
     * 根据code获取字典类型.
     *
     * @param typeCode the type code
     * @return the by type code
     */
    public Dictionary getDictionaryTypeByCode(String typeCode);

    /**
     * 根据字典各层级code获取对应字典及其所有子级数据字典，封装成Tree结构.
     *
     * @param codes the codes
     * @return the by codes
     */
    public Dictionary getDictionaryTreeByCodes(String... codes);

    /**
     * 根据字典类型code获取其子一级数据字典.
     *
     * @param typeCode the type code
     * @return the dictionaries by type code
     */
    public List<Dictionary> getDictionariesByTypeCode(String typeCode);

    /**
     * 根据parent id获取其子一级数据字典.
     *
     * @param parentId the parent id
     * @return the dictionaries by type code
     */
    public List<Dictionary> getDictionariesByParentId(String parentId);

    /**
     * 根据字典类型code获取其所有子级数据字典.
     *
     * @param typeCode the type code
     * @return the all dictionaries by type code
     */
    @Deprecated
    public List<Dictionary> getAllDictionariesByTypeCode(String typeCode);
}
